package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.LeasePublishEntity;
import com.sgb.kjwl.view.ui.adapter.machine.LeasePublishPopAdapter;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;
import com.swgk.core.recyclerview.adapter.PageRecycleAdapter;

import java.util.List;

public class LeasePublishDialog extends BaseBottomDialog {
    private RecyclerView rl_rv_menu;
    private TextView tv_cancel;
    private LeasePublishPopAdapter menuAdapter;
    private DialogClickCallBack dialogClickCallBack;

    public LeasePublishDialog(Context context, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.popwindow_lease_publish;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        rl_rv_menu = holder.getDialog().findViewById(R.id.rv_menu);
        tv_cancel = holder.getDialog().findViewById(R.id.img_close);
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        menuAdapter = new LeasePublishPopAdapter(context, null);
        rl_rv_menu.setLayoutManager(new GridLayoutManager(context, 5));
        rl_rv_menu.setAdapter(menuAdapter);
        menuAdapter.setOnItemClick(new PageRecycleAdapter.OnItemClick<LeasePublishEntity>() {
            @Override
            public void onClick(LeasePublishEntity entity, int position) {
                dialogClickCallBack.onItemClick(entity.getIcon());
                dismiss();
            }
        });
    }

    public void setData(List<LeasePublishEntity> data) {
        menuAdapter.setDatas(data);
    }

    public interface DialogClickCallBack {
        void onItemClick(String resId);
    }

    public LeasePublishDialog setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }

}
